set - set a shell variable, or report values of set variables
SYNTAX
set
set varname1 [varname2...]
set varname1 = value [varname2...]
set varname = (value1 value2...) [varname2...]
DESCRIPTION
Set has two general forms: without arguments and with arguments. Without arguments, set simply causes a list of all currently defined shell variables to be reported to its standard output. With arguments, set defines or redefines a shell variable and its value.
A shell variable may take a value of zero or more words. If the value consists of more than one word, the individual words may be selected by means of an index value in square brackets immediately following the variable name. Index values begin at 1. Supplying an index value of zero is an error.
The following are the forms of "set" involving variable name arguments, descriptions of what they do. Although it isn't shown here, many variables or variable-value pairs may appear on a single command line.
set varname
Create the variable named "varname." Its value will be a single null word.
set varname = value
Create the variable "varname." Its value will be the word "value."
set varname = ()
Create the variable "varname." It's value will be null (zero words).
set varname = (val1 val2)
Create the variable "varname." It's value will be two words: "val1" and "val2"
set varname[1] = val3
Assuming this invocation succeeded the one above, this would reset the first word of varname from "val1" to "val3." Note that it is an error to use an indexed variable with set that exceeds the number of words already defined for a the variable in question.
SHELL VARIABLE EXAMPLES
Suppose the following shell variables were set as shown:
set a=1
set b=abc
set c
set d=()
set e=(1 2 3)
set e[1]=4
Here are some simple examples using the shell utility "echo" to report the results of variable substitution with the variables defined above: (See the main manual entry for "macshell" for information about the variable substitution mechanism.)